package tablemodels;

import javax.swing.table.DefaultTableModel;

/**
 * 
 * @author dernasherbrezon
 *
 */
public class RiskModel extends DefaultTableModel
{
	public String[] riskName = new String[20]; 
	public String[] header = new String[]{"Код риска","Сущность риска"};
	
	
	
	@Override
	public int getColumnCount()
	{
		return 2;
	}
	
	@Override
	public int getRowCount()
	{
		if(riskName!=null)
		{
			return riskName.length;
		}
		return 0;
	}
	@Override
	public String getColumnName(int column)
	{
		return header[column];
	}
	
	@Override
	public boolean isCellEditable(int row, int column)
	{
		if(column==0)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	
	@Override
	public Object getValueAt(int row, int column)
	{
		if(column==0)
		{
			return row+1;
		}
		else
		{
			return riskName[row];
		}
	}
	
	@Override
	public void setValueAt(Object aValue, int row, int column)
	{
		riskName[row] = (String)aValue;
	}
	
	public void checkCorrectValues() throws Exception
	{
		for(int i=0;i<riskName.length;i++)
		{
			if(riskName[i].length()==0)
			{
				throw new Exception("Необходимо указать все 20 рисков!");
			}
		}
	}
}
